Skip to content

Refactor query history to handle remote and local#1143

Merged
aeisenberg merged 4 commits intomainfrom
aeisenberg/refactor-query-history-info
Feb 22, 2022
Merged

Refactor query history to handle remote and local#1143
aeisenberg merged 4 commits intomainfrom
aeisenberg/refactor-query-history-info

Conversation

@aeisenberg
Copy link
Copy Markdown
Contributor

This is a step on the way towards storing remote query history across
restarts.

This PR adds a QueryHistoryInfo type that is a union of two types:
LocalQueryInfo and RemoteQueryInfo.

LocalQueryInfo used to be called FullQueryInfo and RemoteQueryInfo
is only a skeleton right now. The body will be added later. This PR
only introduces it and changes types to make future PRs simpler.

Also, slurp and splat have been moved to the query-serialization.ts
module.

Checklist

  • [n/a] CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [n/a] [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@aeisenberg aeisenberg requested review from a team as code owners February 14, 2022 22:15
Comment thread extensions/ql-vscode/src/query-history.ts
): Promise<void> {
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
if (!this.assertSingleQuery(finalMultiSelect)) {
if (!this.assertSingleQuery(finalMultiSelect) || finalSingleItem.t !== 'local') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Optional) We could have a TODO here like we do in other places.

Same with handleShowQueryText, handleViewSarifAlerts etc.

Comment thread extensions/ql-vscode/src/query-history.ts Outdated

(finalMultiSelect || [finalSingleItem]).forEach((item) => {
if (item.status === QueryStatus.InProgress) {
if (item.status === QueryStatus.InProgress && item.t === 'local') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a comment here saying that we don't currently support cancellation of remote queries.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant with this is that it'd be nice to be clear that we're not planning to support cancellation yet vs we're going to do it in the next PR or something like that.

Comment thread extensions/ql-vscode/src/remote-queries/remote-query-info.ts Outdated
This is a step on the way towards storing remote query history across
restarts.

This PR adds a `QueryHistoryInfo` type that is a union of two types:
`LocalQueryInfo` and `RemoteQueryInfo`.

`LocalQueryInfo` used to be called `FullQueryInfo` and `RemoteQueryInfo`
is only a skeleton right now. The body will be added later. This PR
only introduces it and changes types to make future PRs simpler.

Also, `slurp` and `splat` have been moved to the `query-serialization.ts`
module.
@aeisenberg aeisenberg force-pushed the aeisenberg/remote-queries-history branch from 5daab89 to 39f9c08 Compare February 15, 2022 21:09
@aeisenberg aeisenberg force-pushed the aeisenberg/refactor-query-history-info branch from 21aa7b8 to c78802a Compare February 15, 2022 21:25
Comment thread extensions/ql-vscode/src/query-history.ts Outdated
Comment on lines +628 to +629
singleItem: LocalQueryInfo,
multiSelect: LocalQueryInfo[]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
singleItem: LocalQueryInfo,
multiSelect: LocalQueryInfo[]
singleItem: QueryHistoryInfo,
multiSelect: QueryHistoryInfo[]

Comment on lines +602 to +603
singleItem: LocalQueryInfo,
multiSelect: LocalQueryInfo[]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to do this:

Suggested change
singleItem: LocalQueryInfo,
multiSelect: LocalQueryInfo[]
singleItem: QueryHistoryInfo,
multiSelect: QueryHistoryInfo[]

@charisk
Copy link
Copy Markdown
Contributor

charisk commented Feb 16, 2022

Am I right thinking that I should wait for you to take another pass at the code/comments before I re-review @aeisenberg ?

@aeisenberg
Copy link
Copy Markdown
Contributor Author

Yes. Going through this again now.

Also, rename RemoteQueryInfo -> RemoteQueryHistoryItem
Copy link
Copy Markdown
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor suggestions from my previous review (see unresolved comments)

Base automatically changed from aeisenberg/remote-queries-history to main February 17, 2022 20:35
@aeisenberg
Copy link
Copy Markdown
Contributor Author

I think you're asking to clearly note which commands we plan on supporting for remote queries and which ones we won't. I can add TODOs for the ones we will implement, and regular comments for those we won't.

// TODO will support remote queries
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
if (!this.assertSingleQuery(finalMultiSelect) || finalSingleItem.t !== 'local') {
if (!this.assertSingleQuery(finalMultiSelect) || (finalSingleItem && finalSingleItem.t !== 'local')) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you're not doing finalSingleItem?.t !== 'local' like in other places?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In this case, if the selected query is remote, then we want this command to do nothing. If there is no selection, then we want to throw an error. It is trying to preserve previous behaviour.

However, in a future PR, I got rid of the throw clause. It's actually really difficult for a user to get into a situation where this command is invoked, but no query is selected. Also, if it does happen, then popping up an error message is a bit annoying.

So, for this PR, I was just planning on maintaining previous behaviour.

@aeisenberg aeisenberg merged commit ebce282 into main Feb 22, 2022
@aeisenberg aeisenberg deleted the aeisenberg/refactor-query-history-info branch February 22, 2022 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants